<template>
	<view class="page">
		<navbar title="蜂竞技-排行榜单" :showRank="false" />
		<view class="under-nav">
			<view class="sel-con">
				<selectOpt ref="select1" :options="opt1" :val="val1" :name="name1" @change="opt1Change"
					@fnReset="fnReset"></selectOpt>
				<selectOpt ref="select2" :options="opt2" :val="val2" :name="name2" @change="opt2Change"
					@fnChangeGrage="fnChangeGrage" @fnChangeClasses="fnChangeClasses" @fnReset="fnReset"></selectOpt>
				<selectOpt ref="select3" :options="opt3" :val="val3" :name="name3" @change="opt3Change"
					@fnReset="fnReset"></selectOpt>
			</view>
			<!-- <view class="levels">
				<view class="level level-a">小学组</view>
				<view class="level">初中组</view>
				<view class="level">高中组</view>
			</view> -->
		</view>
		<view class="page-title">
			｜{{name3}}{{name2}}{{name1}}｜
		</view>
		<view v-if="!list.length" class="noDataPlaceImage">
			<image class="img" src="../../static/image/noDataPlaceImage.png" mode="widthFix"></image>
		</view>
		<view class="rank">
			<view class="rank-bg">
				<view class="rank-title" v-if="list.length">
					<view class="tit1">排名</view>
					<view class="tit2">用户</view>
					<view class="tit3">积分</view>
				</view>
				<view class="rank-item" v-for="(item,index) in list" :key="index">
					<view class="index" :class="index === 0 ? 'index0' : ''">{{index+1}}</view>
					<view class="rank-main">
						<image class="avatar" src="../../static/image/fjj/avatar.png"></image>
						<view class="con">
							<view class="username">
								{{item.user_info.username}}
							</view>
						</view>
					</view>
					<view class="score">
						{{item.total_point}}
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-view">
			<view class="rank-item">
				<view class="index index0">
					<!-- 我未参加比赛显示未上榜，参加比赛显示实际名次 -->
					<image v-if="myRank == 0" class="fail" src="../../static/image/fail.jpg" mode="widthFix"></image>
					<view class="rank-index" v-else>{{myRank}}</view>
				</view>
				<view class="rank-main">
					<image class="avatar" src="../../static/image/fjj/avatar.png"></image>
					<view class="con">
						<view class="username">
							我
						</view>
					</view>
				</view>
				<view class="score">
					{{myScore}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import navbar from '../../components/gamesNav.vue'
	import selectOpt from '../../components/select-option.vue'
	export default {
		components: {
			navbar,
			selectOpt
		},
		data() {
			return {
				group_id: '',
				list: [],
				opt1: [], // opt1: ['周榜', '月榜', '季榜', '半年榜', '年榜'],
				val1: '',
				name1: '',
				opt2: [], // '校园排名', '城市排名', '省排名', '全国排名'
				val2: '',
				name2: '',
				opt3: [], // '极速拼词', '拼词竞技', '字母接龙'
				val3: '1',
				name3: '',
				myScore: 0,
				myRank: 0, // 0-未上榜

				config_2_1: '', //年级
				config_2_2: '', //班级
			};
		},
		onLoad(options) {
			var that = this;
			that.group_id = options.group_id;
			this.getRankSearchTypeInfo()
		},
		methods: {
			fnChangeGrage(grade) {
				if (grade != '全部') {
					console.log("grade", grade)
					this.config_2_1 = grade;
				} else {
					this.config_2_1 = "";
				}
				this.getRankList()
			},
			fnChangeClasses(classes) {
				console.log("classes", classes)
				if (classes != '全部') {
					console.log("classes", classes)
					this.config_2_2 = classes;
				} else {
					this.config_2_2 = "";
				}

				this.getRankList()
			},
			fnReset(name) {
				if (name == "周榜") {
					this.$refs.select2.closeFn()
					this.$refs.select3.closeFn()
				}
				if (name == '学校排名' || name == '全省排名' || name == '全市排名' || name == '全区排名' || name == '全国排名') {
					this.$refs.select1.closeFn()
					this.$refs.select3.closeFn()
				}
				if (name == "拼词竞技") {
					this.$refs.select1.closeFn()
					this.$refs.select2.closeFn()
				}
			},
			getRankSearchTypeInfo() {
				this.$http.getRankSearchTypeInfo().then(res => {
					if (res.code === 200) {
						this.opt1 = res.data.config_1
						this.val1 = this.opt1[0].id + ''
						this.name1 = this.opt1[0].name

						this.opt2 = res.data.config_2
						this.val2 = this.opt2[0].id + ''
						this.name2 = this.opt2[0].name

						this.opt3 = res.data.config_3
						this.val3 = this.opt3[0].id + ''
						this.name3 = this.opt3[0].name

						this.getRankList();
					}
				})
			},
			// 获取排行榜列表
			getRankList() {
				const userId = JSON.parse(uni.getStorageSync('USER_INFO')).id
				this.$http.getBigRankList({
					config_1: this.val1,
					config_2: this.val2,
					config_3: this.val3,
					config_2_1: this.config_2_1,
					config_2_2: this.config_2_2
				}).then(res => {
					if (res.code === 200) {
						this.list = res.data
						this.list.forEach((item, i) => {
							if (item.user_id == userId) {
								this.myScore = item.total_point
								if (i <= 9) {
									this.myRank = i + 1
								}
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: '',
							duration: 2000
						})
					}
				})
			},

			opt1Change(e) {
				this.val1 = e.id
				this.name1 = e.name
				this.getRankList()
			},
			opt2Change(e) {
				this.val2 = e.id
				this.name2 = e.name
				this.getRankList()
			},
			opt3Change(e) {
				this.val3 = e.id
				this.name3 = e.name
				this.getRankList()
			}
		}
	}
</script>

<style lang="less">
	.page {
		height: calc(100vh - 84px);
		background: #161001;
		overflow-y: auto;
	}

	.title {
		font-family: hzgb;
		font-size: 18px;
		color: #fff;
		background: linear-gradient(to bottom, #000, #373632);
		text-align: center;
		height: 44px;
		line-height: 44px;
	}

	.rank {
		background: linear-gradient(to right, #fff497, #ffd16b);
		border-radius: 16px;
		margin: 24px 12px;
	}

	.rank-bg {
		background-image: url(../../static/image/homePage/diwen1.png);
		background-size: 100% auto;
		background-repeat: repeat-y;
		border-radius: 16px;
		padding: 0 12px;
	}

	.rank-title {
		display: flex;
		align-items: center;
		font-size: 14px;
		font-family: hzgb;
		height: 32px;
	}

	.rank-item {
		min-height: 56px;
		border-top: 2px solid #000;
		display: flex;
		align-items: center;

		.index {
			width: 40px;
			height: 40px;
			background-image: url(../../static/image/fjj/rank.png);
			background-size: cover;
			font-size: 20px;
			font-family: hzgb;
			color: #fff;
			text-align: center;
			line-height: 32px;
		}

		.index0 {
			background-image: url(../../static/image/fjj/rank1.png);
			color: #ffd16b;
		}

		.score {
			width: 60px;
			text-align: center;
			font-size: 20px;
			font-family: hzgb;
		}
	}

	.rank-main {
		flex: 1;
		display: flex;
		align-items: center;
		margin-left: 20px;

		.avatar {
			width: 40px;
			height: 40px;
			border-radius: 40px;
		}

		.username {
			color: #000;
			font-size: 16px;
			font-family: hzgb;
			margin-bottom: 4px;
			padding-left: 12px;
		}

		.num {
			width: 120px;
			background-color: #000;
			height: 24px;
			line-height: 24px;
			border-radius: 24px;
			text-align: center;
			color: #fff;
			font-size: 14px;
			margin-top: 6px;
		}
	}

	.btn {
		width: 130px;
		height: 40px;
		line-height: 40px;
		box-shadow: 0 6px 0 0 #d9b059;
		background: linear-gradient(to top, #fff497, #ffd16b);
		border-radius: 40px;
		margin: 40px auto;
		text-align: center;
		font-family: hzgb;
		font-size: 16px;
	}

	.tit1 {
		width: 40px;
		text-align: center;
	}

	.tit3 {
		width: 60px;
		text-align: center;
	}

	.tit2 {
		flex: 1;
		padding-left: 70px;
	}

	.bottom-view {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		height: 84px;
		background: linear-gradient(to bottom, #140e01, #313029);
		padding-left: 20px;
		padding-right: 20px;
		padding-top: 12px;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.rank-item {
			border-top: 0;
			color: #fff;

			.username {
				color: #fff;
			}

			.avatar {
				border: 3px solid #ffd16b;
				width: 48px;
				height: 48px;
			}

			.index {
				border-radius: 100%;
				border: 3px solid #ffd16b;
			}
		}

		.fail {
			width: 50px;
			position: relative;
			left: -8px;
		}
	}

	.levels {
		display: flex;
		align-items: center;
		justify-content: space-around;
		padding: 0 12px 24px;

		.level {
			font-family: hzgb;
			color: #fff;
			background: linear-gradient(to top, #373632, #130e00);
			width: 100px;
			text-align: center;
			height: 32px;
			line-height: 32px;
			box-shadow: 0 6px 0 0 #9b8b6f;
			border-radius: 6px;
		}

		.level-a {
			background: linear-gradient(to bottom, #ffd16b, #fff497);
			box-shadow: 0 6px 0 0 #d9b059;
			color: #000;
		}
	}

	.under-nav {
		background: linear-gradient(to bottom, #1c170d, #373632);
	}

	.sel-con {
		padding: 24px 12px;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.page-title {
		width: 100%;
		text-align: center;
		color: #fff;
		font-size: 18px;
		font-family: hzgb;
		margin-top: 24px;
	}

	.noDataPlaceImage {
		text-align: center;
		padding-top: 40px;

		.img {
			width: 40%;
		}
	}

	.rank-index {
		font-size: 32px;
		line-height: 18px;
	}
</style>